<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
$where =" a.id=b.orderid and b.goodsid=c.id ";
$where.=' and a.status = 4 ';
$datelimit_start=empty($_POST['datelimit-start'])?mktime(0,0,0):strtotime($_POST['datelimit-start']);
$datelimit_end=empty($_POST['datelimit-end'])?mktime(0,0,0):strtotime($_POST['datelimit-end']);
$where.=" and UNIX_TIMESTAMP(a.time_day)>=".($datelimit_start)." and UNIX_TIMESTAMP(a.time_day)<=".($datelimit_end+86400-1)."";
$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);

$item=array('starttime'=>$datelimit_start,'endtime'=>$datelimit_end);
if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="a.id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by a.id desc";
}

$total=$ezhand->count("shopping3_order ","status = 4  and UNIX_TIMESTAMP(time_day)>=".($datelimit_start)." and UNIX_TIMESTAMP(time_day)<=".($datelimit_end+86400-1)."");
$row=$ezhand->select_all("shopping3_order a ,shopping3_order_goods b,shopping3_goods c",'a.ordersn,a.guest_name,a.guest_address,a.totalprice,a.status,a.time_day,b.total,a.totalprice,c.basicprice',''.$where.' '.$order.' limit '.$frmnum.','.$pagesize);

foreach($row as $key=>$val){
    $row[$key]['chengben']=$val['basicprice']*$val['total'];
}
$row_list=array();
foreach($row as $key=>$val){
    $ordersn=$val['ordersn'];
    $row_list[$ordersn]['chengben']+=$val['chengben'];
    $row_list[$ordersn]['guest_name']=$val['guest_name'];
    $row_list[$ordersn]['guest_address']=$val['guest_address'];
    $row_list[$ordersn]['totalprice']=$val['totalprice'];
    $row_list[$ordersn]['status']=$val['status'];
    $row_list[$ordersn]['time_day']=$val['time_day'];
    
}
foreach($row_list as $key=>$val){
    $row_list[$key]['maoli']=$val['totalprice']-$val['chengben'];
    $nums['totalmaoli']+=$row_list[$key]['maoli'];
    
}
?>
